package com.v2future.sjt.collegecheckingattendance.rollcall.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.leave.bean.CourseUnitBean;
import com.v2future.sjt.collegecheckingattendance.rollcall.bean.SubjectBean;

import java.util.List;

/**
 * Created by Administrator on 2016/2/17.
 */
public class RollCallCourseAdapter extends BaseAdapter {

    Context mContext;
    List<SubjectBean> dataList;

    public RollCallCourseAdapter(Context mContext, List<SubjectBean> dataList) {
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        SubjectBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_text_check, null);
            holder = new ViewHolder();
            holder.tv_key = (TextView) convertView.findViewById(R.id.tv_key);
            holder.cb_select = (CheckBox) convertView.findViewById(R.id.cb_select);
            holder.tv_course_number = (TextView) convertView.findViewById(R.id.tv_course_number);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_key.setText(bean.getCourseName());
        holder.cb_select.setChecked(bean.isChecked());
        if (!TextUtils.isEmpty(bean.getCourseNumber())) {
            holder.tv_course_number.setVisibility(View.VISIBLE);
            holder.tv_course_number.setText(bean.getCourseNumber());
        }
        else {
            holder.tv_course_number.setVisibility(View.GONE);
        }
        return convertView;
    }

    public class ViewHolder {
        TextView tv_key;
        CheckBox cb_select;
        TextView tv_course_number;
    }
}
